<%@ page language="java" pageEncoding="UTF-8"
	errorPage="/ui/defaultException.jsp"%>
<%@include file="/ui/tags.jsp"%>
<html>
<head>
<title>国家信息</title>
<%@include file="/ui/head.jsp"%>
</head>
<body>


	<table id="list_data" cellspacing="0" cellpadding="0">
		<thead>
			<tr>
				
				<th field="name">行程名称</th>
				<th field="price">行程价格</th>
				<th field="departureCity">出发城市</th>
				<th field="departureDate">出发日期</th>
				<th field="status" formatter="tripStatus">行程状态</th>
				<th field="bookUrl">预订行程的url</th>
				<th field="image" formatter="tripImage">行程图片</th>
				<th field="distance">行程路程</th>
				<th field="days">行程天数</th>
			</tr>
		</thead>
	</table>
	<div id="tripDialog"
		style="width: 400px; height: 280px; padding: 10px 20px" closed="true">
	</div>

	<script type="text/javascript">
		//function manageTrip(value, row, index) {
			//return "<a href='${cpath }/trip/edit/add-destination?tid="
				//	+ row.tripId + "' target='_blank'>编辑行程</a>";
		//}
		function tripImage(value, row, index) {
			return "<img src='${image_domain}" + value
					+ "@!small' width='150' height='100'>";
		}
		var status = {
			'3' : '已审核',
			'2' : '未审核',
			'1' : '编辑状态'
		};
		function tripStatus(value, row, index) {
			return status[value];
		}
	</script>


	<script type="text/javascript">
		$('#list_data').datagrid({
			title : '行程信息',
			iconCls : 'icon-edit',//图标 
			width : 1024,
			height : 'auto',
			nowrap : false,
			striped : true,
			border : true,
			collapsible : false,//是否可折叠的 
			fitColumns : true,//自动大小 
			fit : true,
			url : '${cpath }/admin/trip/expire/list',
			//sortName: 'code', 
			//sortOrder: 'desc', 
			remoteSort : false,
			idField : 'tripId',
			singleSelect : true,//是否单选 
			pagination : true,//分页控件 
			rownumbers : true,//行号  
			toolbar : [ {
				text : '修改行程信息',
				iconCls : 'icon-edit',
				handler : function() {
					var saveAction = cpath + '/admin/trip/update';
					var openAction = cpath + '/admin/trip/vupdate';
					openUpdateTripDialog('修改行程信息', openAction, saveAction);
				}
			}, '-', {
				text : '刷新',
				iconCls : 'icon-reload',
				handler : function() {
					$('#list_data').datagrid('reload');
					save_status = false;
				}
			} ]
		});
		//设置分页控件 
		var p = $('#list_data').datagrid('getPager');
		$(p).pagination({
			pageSize : 10,//每页显示的记录条数，默认为10 
			pageList : [ 5, 10, 15 ],//可以设置每页记录条数的列表 
			beforePageText : '第',//页数文本框前显示的汉字 
			afterPageText : '页    共 {pages} 页',
			displayMsg : '当前显示 {from} - {to} 条记录   共 {total} 条记录'
		/*onBeforeRefresh:function(){
		    $(this).pagination('loading');
		    alert('before refresh');
		    $(this).pagination('loaded');
		}*/
		});
		function vsaveTrip() {
			   window.open("${cpath }/trip/edit/add-destination?tid=0","_blank");
		}
	</script>

	<script type="text/javascript">
		var cpath = '${cpath}';
		function openUpdateTripDialog(dlgtitle, openAction, saveAction) {
			var row = $('#list_data').datagrid('getSelected');
			if (!row) {
				$.messager.alert('提示', "请选择要修改的行程信息!", 'info');
				return;
			}
			openAction = openAction + '?tripId=' + row.tripId;

			$('#tripDialog').dialog({
				title : dlgtitle,
				width : 800,
				height : 550,
				closed : false,
				cache : false,
				resizable : true,
				href : openAction,
				modal : true,
				closed : true,
				buttons : [ {
					text : '保存',
					iconCls : "icon-ok",
					handler : function() {
						saveForm(saveAction);
					}
				}, {
					text : '取消',
					iconCls : "icon-cancel",
					handler : function() {
						$('#tripDialog').dialog('close');
						$('#list_data').datagrid('clearSelections');
					}
				} ]
			});
			$('#tripDialog').dialog('open');
		}
		var save_status = false;

		function saveForm(saveAction) {
			if (save_status) {
				$.messager.alert("提示", "请耐心等待。。。后台执行中。。。", "info");
				return;
			}
			save_status = true;
			$('#fm').form('submit', {
				url : saveAction,
				onSubmit : function() {
					var result = $(this).form('validate');
					if (!result) {
						save_status = false;
					}
					return result;
				},
				success : function(result) {
					var result = eval('(' + result + ')');
					if (result.resultCode !== '00000000') {
						$.messager.alert("错误", result.resultMsg, "error");
						$('#list_data').datagrid('clearSelections');
					} else {
						$.messager.alert("成功", result.resultMsg, "info");
						$('#tripDialog').dialog('close');
						$('#list_data').datagrid('reload');
						$('#list_data').datagrid('clearSelections');
					}
					save_status = false;
				}
			});
		}
	</script>
	<style type="text/css">
#fm {
	margin: 0;
	padding: 10px 30px;
}

.ftitle {
	font-size: 14px;
	font-weight: bold;
	padding: 5px 0;
	margin-bottom: 10px;
	border-bottom: 1px solid #ccc;
}

.fitem {
	margin-bottom: 5px;
}

.fitem label {
	display: inline-block;
	width: 80px;
}
</style>
</body>
</html>